const Koa = require("koa")
const logger = require("koa-logger")
const log4js = require("log4js")
const axios = require("axios")
const moment = require("moment")
const app = new Koa();
const log4 = log4js.getLogger();

//日志打印
app.use(
  logger((info: any) => {
    log4.debug(info);
  })
);
log4.level = "debug";

app.use(async (ctx: any, next: () => any) => {
  const start = Date.now()
  await next();
  axios
    .get("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx7c8148fa23a8b4ff&secret=f8cf95e2fbcbe455c841df2d70eef0ce")
    .then((response:any) => {
      log4.debug("路径",response.config.url);
      log4.debug("内容",response.data);
    })
    .catch((error: any) => {
      log4.debug(error);
    });
  ctx.body = "Hello World";
  const ms = (Date.now() as number) - start
  const currentTime = moment().format("YYYY-MM-DD HH:mm:ss")
  console.log(`${ctx.method} ${ctx.url} - ${ms}ms 时间：${currentTime}`)
});
app.listen(3999);
